package cn.db101.kaoqinserver.config;

import com.baidu.aip.face.AipFace;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.annotation.MapperScans;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@MapperScan(basePackages = "cn.db101.kaoqinserver.mapper")
@EnableConfigurationProperties(FacePropertiesConfig.class)
public class KaoQinConfig implements WebMvcConfigurer {

    /**
     * 资源的配置处理
     */
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //获取项目运行的绝对路径
        String filePath = System.getProperty("user.dir");
        //定义一个存放图片的文件目录
        String localtion = "file:" + filePath + "\\src\\main\\resources\\static\\images\\";
        // 只要是/images/** 开头的请求网址  都会去上面的localtion中寻找资讯
        registry.addResourceHandler("/images/**").
                addResourceLocations(localtion);
    }

    @Bean
    public AipFace aipClient(FacePropertiesConfig facePropertiesConfig) {

        return new AipFace(facePropertiesConfig.getAppId(), facePropertiesConfig.getApiKey(), facePropertiesConfig.getSecretKey());
    }
}
